package com.jzg.jcptadmin.adpter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jzg.jcptadmin.R;
import com.jzg.jcptadmin.data.vo.History;
import com.jzg.template.refreshrecycleview.RefreshBaseAdapter;
import com.jzg.template.refreshrecycleview.RefreshEntity;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by wangyd on 16/1/7.
 */
public class HistoryAdapter extends RefreshBaseAdapter {

    private Context context;
    private List<History> datas;

    public HistoryAdapter(Context context, List<History> datas) {
        super(context, datas);
        this.context = context;
        this.datas = datas;
    }

    @Override
    public int getItemCount() {
        if (datas.size() < 10)
            return datas.size();
        return super.getItemCount();
    }

    public void update(List<History> datas) {
        this.datas = datas;
        this.notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder getHolderView(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.history_item, null));
    }

    @Override
    public void onBindView(RecyclerView.ViewHolder holder, int position, RefreshEntity entity) {
        History history = (History) entity;
        MyViewHolder myViewHolder = (MyViewHolder) holder;
        myViewHolder.full_name.setText(history.getStyleFullName());
        myViewHolder.price.setText(history.getPrice()+"万元");
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.full_name)
        TextView full_name;
        @Bind(R.id.price)
        TextView price;
        @Bind(R.id.price_title)
        TextView price_title;

        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
